home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSGETRF.C < prev    next >
Text File  |  1991-09-23  |  3KB  |  106 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsgetrf.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13. #ifdef AC_STRING
  14. #include <string.h>
  15. #endif
  16.  
  17. /* library headers */
  18. #include <blkio.h>
  19.  
  20. /* local headers */
  21. #include "lseq_.h"
  22.  
  23. /*man---------------------------------------------------------------------------
  24. NAME
  25.      lsgetrf - get field from current lseq record
  26.  
  27. SYNOPSIS
  28.      #include <lseq.h>
  29.  
  30.      int lsgetrf(lsp, offset, buf, bufsize)
  31.      lseq_t *lsp;
  32.      size_t offset;
  33.      void *buf;
  34.      size_t bufsize;
  35.  
  36. DESCRIPTION
  37.      The lsgetrf function reads a field from the current record in
  38.      lseq lsp into buf.  The field begins offset characters from the
  39.      beginning of the record and is bufsize characters long.  buf must
  40.      point to a storage area at least bufsize characters long.
  41.  
  42.      lsgetrf will fail if one or more of the following is true:
  43.  
  44.      [EINVAL]       lsp is not a valid lseq pointer.
  45.      [EINVAL]       buf is the NULL pointer.
  46.      [EINVAL]       bufsize is less than 1.
  47.      [LSEBOUND]     offset + bufsize extends beyond the end of the
  48.                     record.
  49.      [LSELOCK]      lsp is not read locked.
  50.      [LSENOPEN]     lsp is not open.
  51.      [LSENREC]      The cursor is null.
  52.  
  53. SEE ALSO
  54.      lscursor, lsgetr, lsputrf.
  55.  
  56. DIAGNOSTICS
  57.      Upon successful completion, a value of 0 is returned.  Otherwise,
  58.      a value of -1 is returned, and errno set to indicate the error.
  59.  
  60. ------------------------------------------------------------------------------*/
  61. #ifdef AC_PROTO
  62. int lsgetrf(lseq_t *lsp, size_t offset, void *buf, size_t bufsize)
  63. #else
  64. int lsgetrf(lsp, offset, buf, bufsize)
  65. lseq_t *lsp;
  66. size_t offset;
  67. void *buf;
  68. size_t bufsize;
  69. #endif
  70. {
  71.     /* validate arguments */
  72.     if (!ls_valid(lsp) || buf == NULL || bufsize < 1) {
  73.         errno = EINVAL;
  74.         return -1;
  75.     }
  76.  
  77.     /* check if not open */
  78.     if (!(lsp->flags & LSOPEN)) {
  79.         errno = EINVAL;
  80.         return -1;
  81.     }
  82.  
  83.     /* check if not read locked */
  84.     if (!(lsp->flags & LSRDLCK)) {
  85.         errno = LSELOCK;
  86.         return -1;
  87.     }
  88.  
  89.     /* check if over record boundary */
  90.     if (offset + bufsize > lsp->lshdr.recsize) {
  91.         errno = LSEBOUND;
  92.         return -1;
  93.     }
  94.  
  95.     /* check if cursor is null */
  96.     if (lsp->clspos == NIL) {
  97.         errno = LSENREC;
  98.         return -1;
  99.     }
  100.  
  101.     /* copy field from current record */
  102.     memcpy(buf, (char *)lsp->clsrp->recbuf + offset, bufsize);
  103.  
  104.     return 0;
  105. }
  106.